<template>
	<view class="main-class">
			<view class="header-class tn-flex justify-end" >
				<view class="status_bar" style="height: var(--status-bar-height); width: 100%; "></view>
				<tn-navbar height="45px" home-icon="" :bottom-shadow = "false" bg-color="tn-type-primary_bg"> 选择到货地址 </tn-navbar>
				<tn-search-box
					v-model="searchValue"
					@input="searchInputEvent"					@search="searchBtnClickEvent"					size="sm"					placeholder="搜索关键词,检索地址"					placeholder-icon="search"					border-color="#FFFFFF"					text-color="#FFFFFF"					placeholder-color="#FFFFFF"					class="search-class tn-m-sm tn-text-bold"
					search-button-bg-color="#6bb7ec"
					shape="round"
				/>
			</view>
			<view class="client-class">
				<view v-for="(item,index) in addressData" >
					<view class="tn-m-sm" @click="selAddress(item)">
						<view class="tn-text-ellipsis-2 tn-p-xs tn-text-lg">
							{{item.dhrecemanname}} ：{{item.dhrecetelephone}}
						</view>
						<view class="tn-text-ellipsis-2 tn-grey_text tn-text-sm tn-p-xs">
							{{item.dhaddress}}
						</view>
						<hr/>
					</view>	
				</view>
			</view>
	</view>
	
</template>

<script setup>
	import {ref,reactive,onMounted} from 'vue'
	import { postCall  } from '@/api/index.js'
	import { createParams } from '@/utils/utils.js'
	import { EventBus } from '@/mitt/EventBus.js';
	const headerClass = ref('');
	const shopClientInfo = reactive({});
	onMounted(() => {
		Object.assign(shopClientInfo,uni.getStorageSync("SHOPCLIENTINFO"));
		doGetAddress();
	});
	
	let back = (val) =>{
		EventBus.emit('shopClientInfo',val);
		uni.navigateBack();
	}
	const searchValue = ref("");
	const searchInputEvent = () =>{
		
	}
	const searchBtnClickEvent = () =>{
		doGetAddress();
	}
	
	
	
	const procName = "PROC_APP_DO_SHOPPING";
	const addressData = reactive([]);
	let doGetAddress = () =>{
		addressData.length = 0;
		let params = {};
		params["P_PROC_NAME"] = procName;
		params["P_ACTION"] = "DHADDRESS";		
		params["P_CLIENTID"] = shopClientInfo.businessid;	
		params["P_CON"] = searchValue.value;
		postCall(params).then(res=>{
			if(res){
				if(res.code===200){
					res.data.DATASET.forEach(item => {
					  addressData.push(item);
					});
				}
			}	
		})
	}
	
	let selAddress = (val) =>{
		uni.setStorageSync("SHOPCLIENTINFO",Object.assign(uni.getStorageSync("SHOPCLIENTINFO"),val));
		back(val);
	}
	
</script>

<style scoped>
	page{
		overflow: hidden;
	}
	.header-class-app{
		height: 14vh !important;
		flex-direction: column
	 } 
	
	.header-class-wechat{
		height: 17vh !important;
		flex-direction: column
	}
	.header-class{
		height: 17vh !important;
		flex-direction: column;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		background-color: #333;
		color: #fff;
		padding: 10px 0;
		text-align: center;
		z-index: 999 
	}
	hr {
	  border: none;
	  border-top: 1px solid #dedede; 
	}
	.client-class{
		margin-top: 17vh;
	}
</style>